﻿using Elsa.Workflows;
using Elsa.Workflows.Activities;
using Elsa.Workflows.Contracts;
using Elsa.Workflows.Memory;
using Elsa.Workflows.Models;

namespace Elsa.Samples.ConsoleApp.ActivityOutput.Workflows
{
    public class DemoWorkflow : WorkflowBase
    {
        protected override void Build(IWorkflowBuilder builder)
        {
            var name = new Variable<string>();
            builder.Root = new Sequence
            {
                Variables =
                {
                    name
                },
                Activities =
                {
                    new WriteLine("Please input your name"),
                    new ReadLine(name),
                    new WriteLine(x => $"my name is : {name.Get(x)}" )
                }
            };
        }
    }

    public class SumDemoWorkflow : WorkflowBase
    {
        protected override void Build(IWorkflowBuilder builder)
        {
            var arg1 = new Variable<int>();
            var arg2 = new Variable<int>();

            builder.Root = new Sequence
            {
                Variables = { arg1, arg2 },
                Activities =
                {
                    new WriteLine($"Please input arg1"),
                    new ReadLine(arg1),
                    new WriteLine($"Please input arg2"),
                    new ReadLine(arg2),
                    new WriteLine(x => $"The sum result is : { arg1.Get(x) + arg2.Get(x) }")
                }
            };
        }
    }

    public class ForDemoWorkflow : WorkflowBase
    {
        protected override void Build(IWorkflowBuilder builder)
        {
            var currentValue = new Variable<int>();
            builder.Root = new Sequence
            {
                Variables = { currentValue },
                Activities = 
                {
                    new For(0, 10, 1)
                    {
                        CurrentValue = new Output<object?>(currentValue),
                        Body = new Sequence
                        { 
                            Activities =
                            {                                
                                new If(x => currentValue.Get(x) > 5)
                                { 
                                    Then = new WriteLine(x =>  $"Current Value is greate than 5 : { currentValue.Get(x)}" ),
                                    Else = new WriteLine(x =>  $"Current Value is less than 5 : { currentValue.Get(x)}" ),
                                }
                            }
                        },
                    }
                }
            };
        }
    }

    public class SetVarWorkflow : WorkflowBase
    {
        protected override void Build(IWorkflowBuilder builder)
        {
            var name = new Variable<string>();
            builder.Root = new Sequence
            {
                Variables =
                {
                    name
                },
                Activities =
                {
                    new WriteLine("Please input your name"),
                    new SetVariable<string>(name, "carl"),
                    new WriteLine(x => $"my name is : {name.Get(x)}" )
                }
            };
        }
    }
}
